package org.noip.amdg;

import java.awt.event.KeyEvent;

public class Egg {
	private enum State { START, UP, UPUP, DOWN, DOWNDOWN, LEFT, RIGHT, LEFTLEFT, RIGHTRIGHT, B, A }
	
	private State currentState = State.START;
	
	public boolean step(KeyEvent key) {
		switch(currentState) {
		case A:
			currentState = State.START;
			break;
		case B:
			if ('A' == key.getKeyChar() || 'a' == key.getKeyChar()) currentState = State.A;
			else currentState = State.START;
			break;
		case DOWN:
			if (KeyEvent.VK_DOWN == key.getKeyCode()) currentState = State.DOWNDOWN;
			else currentState = State.START;
			break;
		case DOWNDOWN:
			if (KeyEvent.VK_LEFT == key.getKeyCode()) currentState = State.LEFT;
			else currentState = State.START;
			break;
		case LEFT:
			if (KeyEvent.VK_RIGHT == key.getKeyCode()) currentState = State.RIGHT;
			else currentState = State.START;
			break;
		case LEFTLEFT:
			if (KeyEvent.VK_RIGHT == key.getKeyCode()) currentState = State.RIGHTRIGHT;
			else currentState = State.START;
			break;
		case RIGHT:
			if (KeyEvent.VK_LEFT == key.getKeyCode()) currentState = State.LEFTLEFT;
			else currentState = State.START;
			break;
		case RIGHTRIGHT:
			if ('B' == key.getKeyChar() || 'b' == key.getKeyChar()) currentState = State.B;
			else currentState = State.START;
			break;
		case START:
			if (KeyEvent.VK_UP == key.getKeyCode()) currentState = State.UP;
			break;
		case UP:
			if (KeyEvent.VK_UP == key.getKeyCode()) currentState = State.UPUP;
			else currentState = State.START;
			break;
		case UPUP:
			if (KeyEvent.VK_DOWN == key.getKeyCode()) currentState = State.DOWN;
			else currentState = State.START;
			break;
		
		}
		return currentState == State.A;
	}
}
